﻿using System.Web.Mvc;

namespace Kratos.Framework.Infrastructures
{
    public class KratosViewEngine : RazorViewEngine
    {
        public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            string rootModule = controllerContext.Controller.GetType().Assembly.GetName().Name;
            ViewLocationFormats = new[] {
                                          "~/Views/" + rootModule + "/{1}/{0}.cshtml"              //模块/controller/action
                                      };
            MasterLocationFormats = new[] {
                                        "~/Views/" + rootModule + "/Shared/{0}.cshtml"
                                        };
            PartialViewLocationFormats = new[] {
                                        "~/Views/" + rootModule + "/{1}/{0}.cshtml",
                                        "~/Views/" + rootModule + "/Shared/{0}.cshtml"
                                        };

            return base.FindView(controllerContext, viewName, masterName, useCache);
        }

        public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
        {
            return FindView(controllerContext, partialViewName, null, useCache);
        }
    }
}
